<template>
	<view class="wrap">
		<view class="topBc"></view>
		<view class="content formWrap">
			<view class="title" style="margin-top: 0;">特种设备信息</view>
			
			<u-form :model="formData" ref="uForm" :rules="rules">
				<u-form-item label="办理使用登记特种设备总台数" prop="vendinc" required label-width="auto" borderBottom>
					<u-input v-model="formData.vendinc" placeholder="请输入" type="number" border="none" inputAlign="right">
						<u--text
							text="台(套数)"
							slot="suffix"
						></u--text>
					</u-input>
				</u-form-item>
				<u-form-item label="检验有效期内特种设备总台数" prop="vendinc" required label-width="auto" borderBottom>
					<u-input v-model="formData.vendinc" placeholder="请输入" type="number" border="none" inputAlign="right">
						<u--text
							text="台(套数)"
							slot="suffix"
						></u--text>
					</u-input>
				</u-form-item>
			</u-form>
			
			<view class="hint">
				<view class="">
					1、办理使用登记特种设备总台(套)数:特种设备使用单位办理使用登记的特种设备数量，包括锅炉、压力容器(不含气瓶)、电梯、起重机械、大型游乐设施、
					客运索道和场(厂)内专用机动车辆，由实际办理使用登记手续的单位填报。没有上述使用登记设备的填“0”。
				</view>
				<view class="">
					2、检验有效期内特种设备总台(套]数:特种设备使用单位已办理使用登记并在检验合格有效期内的特种设备数量，包括锅炉、压力容器(不含气瓶)、电梯、
					起重机械、大型游乐设施、客运索道和场(厂)内专用机动车辆。
				</view>
			</view>
			
		</view>
		<view class="submitBtn_bc"></view>
		<view class="submitBtn_ubtn">
			<u-button :disabled="!$util.submitState(year,state)" @click="submit()">提交</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data(){
		return{
			minFormName: 'assetinfo', //小表单类型名
			regnoInfo: this.$store.state.regnoInfo,
			year: '',
			state: '',
			bgColor: this.$config.bgColor,
			
			stateRanges: [
				{text: '是',value: '1'},
				{text: '否',value: '2'}
			],
			formData: {
				vendinc: '',
				vendincdis: '',
				ratgro: '',
				ratgrodis: '',
			},
			rules: {},
			rulesAll: {
				vendinc: {type:'number',required: true,message: '内容输入有误',trigger: ['blur','change']},
				vendincdis: {type:'number',required: true,message: '请选择',trigger: ['blur','change']},
				ratgro: {type:'number',required: true,message: '内容输入有误',trigger: ['blur','change']},
				ratgrodis: {type:'number',required: true,message: '请选择',trigger: ['blur','change']},
			},
			formKeys: {},
		}
	},
	onLoad(option) {
		this.year = option.year;
		this.state = option.state;
		this.getFormKey();
		// this.getFormData();
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules)
	},
	methods:{
		// 获取小表单数据
		getFormData(){
			let url = this.$typeData.minFormUrl.get(this.minFormName);
			if(!url){
				uni.showModal({
					title: '暂无接口'
				})
				return;
			}
			this.$http.sendRequest({
				url: url,
				data: {
					regno: this.regnoInfo.regno,
					ancheyear: this.year
				}
			})
			.then(res=>{
				console.log('接口返回',res.data);
				let data = res.data;				let keys = Object.keys(this.formKeys);				keys.forEach(item=>{					this.formData[item] = data[item];				})
				console.log(789789,this.formData);
			})
			.catch(err=>{})
		},
		//获取小表单拥有字段
		getFormKey(){
			let formKeys = this.$util.getFormKeys(this.minFormName,this.regnoInfo.enttype);
			this.formKeys = formKeys;
			let keys = Object.keys(formKeys);
			keys.forEach(item=>{
				this.rules[item] = this.rulesAll[item];
			})
		},
		submit(){
			this.$refs.uForm.validate().then(res => {
				this.saveBtn();
			}).catch(errors => {
				this.$util.showToast({title:'请完善信息'})
			})
		},
		saveBtn(){
			let data = {
				regno: this.regnoInfo.regno,
				ancheyear: this.year,
			}
			data = {...data,...this.formData};
			this.$http.sendRequest({
				url: '/annual/report/baseinfo/update-assetinfo',
				method: 'PUT',
				data: data
			})
			.then(res=>{
				this.setRecord();
			})
			.catch(err=>{})
		},
		
		
		
		
		
		//存一下记录
		setRecord(){
			let fillingItem = this.$minFormType.get(this.minFormName);
			this.$http.sendRequest({
				url: '/annual/report/record',
				method: 'POST',
				data: {
					regno: this.regnoInfo.regno,
					year: this.year,
					fillingItem: fillingItem,
					isImp: '0',
				},
				hideLoad: true,
			})
			.then(res=>{
				uni.navigateBack();
			})
			.catch(err=>{})
		},
		goPage(path){
			uni.navigateTo({
				url: path
			})
		},
	}
}
</script>

<style lang="less" scoped>
.wrap{
	width: 100vw;
	min-height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	position: relative;
	background-color: #FFF;
	
	.topBc{
		height: 10rpx;
		background-color: #F5F6F8;
	}
}

.content{
	padding: 30rpx 36rpx;
	background-color: #FFF;
	
	.title{
		color: #E4B269;
		font-size: 36rpx;
		font-weight: bold;
		border-left: 8rpx solid #E4B269;
		line-height: 40rpx;
		padding-left: 16rpx;
		margin-bottom: 30rpx;
		margin-top: 30rpx;
	}
	
	
}

.hint{
	padding: 10rpx;
	font-size: 30rpx;
	color: red;
	margin-top: 20rpx;
	letter-spacing: 2rpx;
	line-height: 1.5;
	text-indent: 2em;
	
	view{
		margin-bottom: 20rpx;
	}
}


</style>